extends Node2D

var passed:bool=false
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	pass
var can_not_back:bool=false
func _input(event: InputEvent) -> void:
	if can_not_back and not passed:
		if event.is_action_pressed("a"):
			Global.display_str.emit("你的后退让它感到兴奋")
			can_not_back=false
			print("not back")
			%Sun.rush()
			await %Sun.rushed
			%Sun.load_out()
			Global.player_should_death.emit()
			end_test()
		elif event.is_action_pressed("jump"):
			Global.display_str.emit("你的雀跃出卖了你")
			can_not_back=false
			print("not back")
			%Sun.rush()
			await %Sun.rushed
			%Sun.load_out()
			Global.player_should_death.emit()
			end_test()
		elif event.is_action_pressed("d"):
			$CantnotStop.stop()
		elif event.is_action_released("d"):
			$CantnotStop.start()
func _on_start_area_entered(area: Area2D) -> void:
	if not area.is_in_group("player"):return
	Global.fighting=true
	$Start.set_deferred("monitoring",false)
	$TestArea.set_collision_layer_value(1,true)
	Global.display_tip.emit("偷偷的,不停的前进")
	Global.player_movment_mode.emit("tie")
	Global.player_walk_speed.emit(200)
	%Sun.load_in()
	await %Sun.load_finished
	%ColorFull.black()
	Global.player_movment_mode.emit("walk")
	can_not_back=true
	


func _on_cantnot_stop_timeout() -> void:
	if can_not_back:
		print("not stop")
		Global.display_str.emit("你的迟疑害了你")
		%Sun.rush()
		await %Sun.rushed
		%Sun.load_out()
		Global.player_should_death.emit()
		end_test()


func _on_change_pos_area_entered(area: Area2D) -> void:
	if not area.is_in_group("player"):return
	$ChangePos.set_deferred("monitoring",false)
	%Sun.change_pos(1)
	


func _on_change_pos_2_area_entered(area: Area2D) -> void:
	if not area.is_in_group("player"):return
	$ChangePos2.set_deferred("monitoring",false)
	%Sun.change_pos(2)
	await get_tree().create_timer(3).timeout
	%Sun.change_pos(0)


func _on_heart_beat_area_entered(area: Area2D) -> void:
	if not area.is_in_group("player"):return
	$HeartBeat.set_deferred("monitoring",false)
	Global.display_str.emit("什么声音")
	%Sun.heartbeat()


func _on_ghost_2_area_entered(area: Area2D) -> void:
	if not area.is_in_group("player"):return
	$Ghost2.set_deferred("monitoring",false)
	Global.display_str.emit("那是...")
	%Sun.ghost()

func end_test()->void:
	if not passed:
		$Start.set_deferred("monitoring",true)
		$TestArea.set_collision_layer_value(1,false)
		$ChangePos.set_deferred("monitoring",true)
		$ChangePos2.set_deferred("monitoring",true)
		$HeartBeat.set_deferred("monitoring",true)
		$Ghost2.set_deferred("monitoring",true)
	Global.player_walk_speed.emit(400)
	if not passed:%ColorFull.default()
	else:
		%ColorFull.sun()
		Global.display_str.emit("远处的天空中出现了一抹金光")
		$TestArea.set_collision_layer_value(1,false)
	Global.fighting=false


func _on_out_area_entered(area: Area2D) -> void:
	if not area.is_in_group("player"):return
	$Out.set_deferred("monitoring",false)
	passed=true
	%Sun.load_out()
	end_test()
